-- ********************************************
-- * Copyright (c) 2012 TPV R&D Center Brazil *
-- * All Rights Reserved                      *
-- ********************************************

--- toolkit.component.TextBox
local TextBox = Box:new()

function TextBox:new(o)
   if (type(o) ~= 'table') then
      o = {}
   end

   local newTextBox = Box:new(o)

   newTextBox.parent = nil
   
   newTextBox.componentType = "TextBox"

   newTextBox.textContent = nil
   newTextBox.scrollContent = nil

   newTextBox.text = o.text or '' -- text: 

   newTextBox.Activated = {
      size = 18,
      color = {241, 241, 241, 255},
      type = 'Lato',
      style = 'Normal'
   }

   tmpLabel = Label:new({width = o.width, height = 500})
   tmpLabel:setActivated(o.Activated)

   newTextBox.label = o.label or tmpLabel
   newTextBox.label:setText(o.text)
   
   newTextBox.lps = o.lps or 1 -- lps: lines per scroll
   -- DO NOT INSERT VALUE BY APPLICATION
   newTextBox.line = o.line or 0
   newTextBox.maxValue = o.maxValue or -1
   newTextBox.lineSize = o.lineSize 
   --
   newTextBox.scroll = {
      width = 6,
      color = {255, 255, 255, 76}
   }

   --generate an object
   setmetatable(newTextBox, self)
   self.__index = self

   return newTextBox
end

function TextBox:scrollUp()
   if (self.line > 0) then 
      self.line = self.line - self.lps
   end 
	self.parent:updateTextBox(self)
end

function TextBox:scrollDown()
   if (self.line < self.maxValue) then 
      self.line = self.line + self.lps
   end
	self.parent:updateTextBox(self)
end

function TextBox:getText()
   return self.text
end

function TextBox:setText(o)
   if (type(o) == 'string') then
      self.text = o
   end
end

function TextBox:redraw()
   self.parent:update(self)
end

function TextBox:dispose()
   self.scrollContent = nil
   collectgarbage()
end

return TextBox
